home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 9536 / 9536.xpi / chrome / commentsbar_ff.jar / content / commentsbar_ff / widget.js < prev   
Text File  |  2008-12-22  |  11KB  |  286 lines

  1.         var oldValue = 300;
  2.         var alwaysOnTopState = false;
  3.         var isMaximized = true;
  4.         var captionSize = 24;
  5.         var isBorder = false;
  6.         var tool = null;
  7.         var ie = true;
  8.         function ToolBarInit(_tool)
  9.         {
  10.             tool = _tool;
  11.             ie = false;
  12.             onReady();
  13.         }
  14.         function GetProperty(name, value)
  15.         {
  16.             if (tool)
  17.             {
  18.                 return tool.getProperty(name, value);
  19.             } else
  20.                 return window.external.GetProperty(name, value);
  21.         }
  22.         function SetProperty(name, value)
  23.         {
  24.             if (tool)
  25.             {
  26.                 return tool.setProperty(name, value);
  27.             } else
  28.                 return window.external.SetProperty(name, value);
  29.         }        
  30.         function AlwaysOnTopTriger() {
  31.             AlwaysOnTop(alwaysOnTopState);
  32.             alwaysOnTopState = !alwaysOnTopState;
  33.         }
  34.  
  35.         function AlwaysOnTop(b) {
  36.             try{
  37.                 if (b) window.external.SetWindowPos(-2, 0, 0, 0, 0, 3);
  38.                 else window.external.SetWindowPos(-1, 0, 0, 0, 0, 3);
  39.             } catch (err) {}
  40.         }
  41.  
  42.         function MinimizeMaximizeTriger() {
  43.             if (isMaximized) {
  44.                 Minimize();
  45.             }
  46.             else {
  47.                 Maximize();
  48.             }
  49.             isMaximized = !isMaximized;
  50.         }
  51.  
  52.         function BorderTriger() {
  53.             if (isBorder) {
  54.                 BorderOff();
  55.             }
  56.             else {
  57.                 BorderOn();
  58.             }
  59.             isBorder = !isBorder;
  60.         }
  61.  
  62.         function BorderOn() {
  63.             try{
  64.                 //WS_THICKFRAME, SWP_FRAMECHANGED
  65.                 window.external.ModifyStyle(0, 262144, 32);
  66.             } catch (err) {}
  67.             return false;
  68.         }
  69.  
  70.         function BorderOff() {
  71.             try{
  72.                 //WS_THICKFRAME, SWP_FRAMECHANGED
  73.                 window.external.ModifyStyle(262144,0, 32);
  74.             } catch (err) {}
  75.             return false;
  76.         }
  77.  
  78.         function Minimize() {
  79.             if (tool)
  80.             {
  81.                 var size = tool.getSize();
  82.                 oldValue = size[1];
  83.                 tool.resize(size[0], captionSize);         
  84.             } else {
  85.                 try{
  86.                  window.external.GetWindowRect(function(left, top, right, bottom) {
  87.                         oldValue = bottom - top;
  88.                      if (oldValue < 100) oldValue = 100;
  89.                      window.external.MoveWindow(left, top, right - left, captionSize);
  90.                  moveSmoothCorner(right - left, captionSize);
  91.                  document.getElementById("_content").style.display = "none";  
  92.                     });
  93.                 } catch (err) {}
  94.             }
  95.             
  96.             return false;
  97.         }
  98.  
  99.         function Maximize() {
  100.             if (tool)
  101.             {
  102.                 var size = tool.getSize();
  103.                 tool.resize(size[0], oldValue);        
  104.             } else {
  105.                 try{
  106.                     window.external.GetWindowRect(function(left, top, right, bottom) {
  107.                         window.external.MoveWindow(left, top, right - left, oldValue);
  108.                         moveSmoothCorner(right - left, oldValue);
  109.                         document.getElementById("_content").style.display = "block";  
  110.                     });
  111.                 } catch (err) {}
  112.             }
  113.             
  114.             return false;
  115.         }
  116.  
  117.         function Close() {
  118.             if (tool)
  119.             {
  120.                 tool.close();                
  121.             } else
  122.              try{
  123.             setTimeout("smoothChangeTransparency(220, 0, -10)", 10);
  124.                    setTimeout("window.external.Close()", 210);
  125.                 } catch (err) {}
  126.             return false;
  127.         }
  128.  
  129.         function Capturemouse() {
  130.             try{
  131.                  window.external.Capturemouse();
  132.             } catch (err) {}
  133.         }
  134.  
  135.         function whichElement(e) {
  136.             if (tool)
  137.             {
  138.                 tool.captureMouse(e);
  139.                 return;
  140.             }
  141.             var targ
  142.             if (!e) var e = window.event
  143.             if (e.target) targ = e.target
  144.             else if (e.srcElement) targ = e.srcElement
  145.             if (targ.nodeType == 3) // defeat Safari bug
  146.                 targ = targ.parentNode
  147.             var tname
  148.             tname = targ.tagName
  149.             if (tname != "INPUT") Capturemouse()
  150.         }
  151.     function smoothChangeTransparency(from, to, step)
  152.     {
  153.         try
  154.         {
  155.         from += step;
  156.         from = (from > 255) ? 255 : ((from < 0)? 0 : from);
  157.         window.external.MakeWindowTransparent(0xEEFF00, from);
  158.         if ((step>0 && from<=to) || (step<0 && from>=to))
  159.             setTimeout("smoothChangeTransparency("+from+","+to+","+step+")", 10);
  160.         } catch (err) {}
  161.     }
  162.     
  163.         function onReady(){
  164.             try
  165.             {
  166.                 //BorderTriger();
  167.                 
  168.                 var userVarsStr = GetProperty("user_vars","");
  169.                 placeWindowButtons(true, userVarsStr, !tool, true);
  170.                 document.getElementById("_header").innerHTML  = GetProperty("caption","");
  171.                 if (!tool)
  172.                 {
  173.                     AlwaysOnTopTriger();
  174.                     window.external.MakeWindowTransparent(0x00FFEE, 0);
  175.                     placeSmoothCorner();
  176.                 }
  177.                 if (userVarsStr && (GetProperty("first_start","true") == "true"))
  178.                 {
  179.             showSettings();
  180.                 } else {
  181.                     showContent(false);
  182.                 }    
  183.                 if (!tool)
  184.                 {
  185.                     window.external.Show();
  186.                     setTimeout("smoothChangeTransparency(0, 220, 150)", 10);
  187.             }
  188.            } catch (err) {}  
  189.        }
  190.        function prepeareString($0, $1)
  191.        {
  192.                return GetProperty($1, $1);
  193.        }
  194.         function prepeareWidget(src)
  195.         {
  196.             return src.replace(/\[\[(\w*?)\]\]/ig, prepeareString);
  197.         }
  198.         function showSettings()
  199.         {
  200.             var userVarsStr = GetProperty("user_vars","");
  201.             if (userVarsStr)
  202.             {
  203.                 var userVars = eval("(" + userVarsStr + ");");
  204.                 var html = "<center><table>";
  205.             for(variable in userVars)
  206.             {
  207.                    html += "<tr><td class='name_field'>" + userVars[variable].screenName + "</td>";
  208.                 if (userVars[variable].type == "enum")
  209.                 {
  210.                     html += "<td><SELECT class='input_field' id='"+variable+"'>";
  211.                     for(val in userVars[variable].values)
  212.                     {
  213.                         html += "<OPTION value='"+val+"'";
  214.                         if (val == GetProperty(variable,"")) 
  215.                             html += ' SELECTED';
  216.                         html += ">"+userVars[variable].values[val]+"</OPTION>";
  217.                     }
  218.                     html += "</SELECT></TD>";
  219.                 } else {
  220.                     html += "<td><input type='text' class='input_field' id='"+variable+"' value='"+GetProperty(variable,"")+"'></td>";
  221.                 }
  222.             }
  223.                 html += "</tr>";
  224.             html += "<tr><td colspan=2 align=right>";
  225.             html += "<input type=button value='Cancel' class='save_button' onClick='javascript:showContent(false);'>";
  226.             html += "<input type=button value='Save' class='save_button' onClick='javascript:showContent(true);'></td></tr>";
  227.             html += "</table>";
  228.             document.getElementById("_content").innerHTML = html;
  229.         }
  230.         }
  231.         
  232.         function showContent(first_start)
  233.         {
  234.             if(first_start)
  235.             {
  236.         var fields = document.getElementsByTagName('input');
  237.         for (i=0; i<fields.length; i++) {
  238.             SetProperty(fields[i].id, fields[i].value);
  239.         }
  240.         fields = document.getElementsByTagName('select');
  241.         for (i=0; i<fields.length; i++) {
  242.             SetProperty(fields[i].id, fields[i].value);
  243.         }
  244.                 SetProperty("first_start", "false");
  245.             }
  246.             //document.getElementById("_content").innerHTML = "<textarea>" + prepeareWidget(GetProperty("widgetpath","")) + "</textarea>";  
  247.             document.getElementById("_content").innerHTML = prepeareWidget(GetProperty("widgetpath",""));  
  248.             
  249.         }
  250.         function onHover(obj, src)
  251.         {
  252.             obj.src = src;
  253.         }
  254.         
  255.         function placeWindowButtons(bMinimize, bSettings, bOnTop, bClose)
  256.         {
  257.             var buttons = "";
  258.             if (bMinimize) buttons += '<span onmousedown="MinimizeMaximizeTriger();"><img src="minimize.gif"  onMouseOver="onHover(this, \'onminimize.gif\');"  onMouseOut="onHover(this, \'minimize.gif\');"></span>';
  259.             if (bSettings) buttons += '<span onmousedown="showSettings();"><img src="settings.gif"  onMouseOver="onHover(this, \'onsettings.gif\');"  onMouseOut="onHover(this, \'settings.gif\');"></span>';
  260.             if (bOnTop)    buttons += '<span onmousedown="AlwaysOnTopTriger();"><img src="ontop.gif"  onMouseOver="onHover(this, \'onontop.gif\');"  onMouseOut="onHover(this, \'ontop.gif\');"></span>';
  261.             if (bClose)    buttons += '<span onmousedown="Close();"><img src="close.gif" onMouseOver="onHover(this, \'onclose.gif\');"  onMouseOut="onHover(this, \'close.gif\');"></span>';
  262.             buttons += '<span> </span>';
  263.             document.getElementById("_window_buttons").innerHTML = buttons;
  264.         }
  265.         
  266.         function placeSmoothCorner()
  267.         {
  268.             var html = "";
  269.             var width = 1*window.external.GetProperty("width", 0)-6;
  270.             var height = 1*window.external.GetProperty("height", 0)-6;
  271.             html += "<img id=_lt src='lt.gif' border=0 style='position:absolute; top:0px; left:0px;'>";
  272.             html += "<img id=_rt src='rt.gif' border=0 style='position:absolute; top:0px; left:"+width+"px;'>";
  273.             html += "<img id=_rb src='rb.gif' border=0 style='position:absolute; top:"+height+"px; left:"+width+"px;'>";
  274.             html += "<img id=_lb src='lb.gif' border=0 style='position:absolute; top:"+height+"px; left:0px;'>";
  275.             document.body.innerHTML += html;
  276.         }
  277.         function moveSmoothCorner(width, height)
  278.         {
  279.             try{
  280.             document.getElementById("_lb").style.top = 1*height-6 + "px";
  281.             document.getElementById("_rb").style.top = 1*height-6 + "px";
  282.             document.getElementById("_rb").style.left = 1*width-6 + "px";
  283.             document.getElementById("_rt").style.left = 1*width-6 + "px";    
  284.             } catch(err){}
  285.         }
  286.